const { Client } = require("./client");

// 创建两个客户端
const A = new Client("A");
const B = new Client("B");

// 客户端A插入一些字符
const a1 = A.insert(0, "a");
const a2 = A.insert(1, "b");
const a3 = A.insert(2, "c");
console.log("------------------");

// 接下来将上面的操作同步到客户端B
B.receive({ type: "insert", char: a1 });
B.receive({ type: "insert", char: a2 });
B.receive({ type: "insert", char: a3 });
console.log("------------------");

// 客户端B插入一个 X 在最前面
const b1 = B.insert(0, "X");
// 接下来将这个操作同步给客户端A
A.receive({ type: "insert", char: b1 });
console.log("------------------");

// 接下来客户端A删除字符b
const a4 = A.delete(2);
// 接下来将这个操作同步给客户端B
B.receive({ type: "delete", id: a4.id });
